package com.kong.controller;


import com.kong.User;
import com.kong.jwt.JwtToken;
import com.kong.jwt.JwtUtil;
import com.kong.redis.IRedisService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;


/**
 *
 * @author  k
 */
@RestController
@Slf4j
public class UserController {

    @Resource
    IRedisService redisService;


    @PostMapping("/login")
    public String login(@RequestBody User user) {

        log.info("{}",user);
        return JwtUtil.sign(user.getName(), user.getPassword());
    }

    @PostMapping("/selectById")
    public String selectById(@RequestHeader("token") String token) {
        System.out.println(token);
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        Serializable id = session.getId();

        System.out.println(session.getAttributeKeys());
        String username = JwtUtil.getUsername(token);
        System.out.println(username);
        return token;
    }

}
